Skip to content

Conversation

zifeif2
Copy link

@zifeif2 zifeif2 commented Oct 6, 2025

…usage is enabled

What changes were proposed in this pull request?

Changing the way we calculate pinnedBlocksMemUsage when an instance has bounded memory enabled.
Before the change, we always report back getDBProperty("rocksdb.block-cache-pinned-usage") which returns that size of pinned block requested by an instance. This is not accurate when instances share the same cached, because instances might share the same pinned block

After this change, when isMemoryBounded is enabled for an instance, we call lruCache.getPinnedUsage() to get the total memory usage of SHARED pinned blocks, and divide the global usage with the number of IS_MEMORY_BOUNDED instances. This is because RocksDBMemoryManager will return the same cache for all the instance that has isMemoryBounded = true

Unit test:
build/mvn -Dtest=none -DwildcardSuites=org.apache.spark.sql.execution.streaming.state.RocksDBSuite test

Why are the changes needed?

See above for why this is a bug.
This fix prevents us from over-reporting pinnedBlocksMemUsage when isBoundedMemory is enabled for an instance

Does this PR introduce any user-facing change?

No

How was this patch tested?

See added unit tests on the correctness of the calculation.

Was this patch authored or co-authored using generative AI tooling?

Yes. Generated-by cursor and 'claude-4-sonnet'

@zifeif2 zifeif2 changed the title [SPARK-53792] Fix rocksdbPinnedBlocksMemoryUsage when bounded memory … [SPARK-53792][SS] Fix rocksdbPinnedBlocksMemoryUsage when bounded memory … Oct 7, 2025
Copy link
Contributor

@micheal-o micheal-o left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM! Just one final nit. Thanks

*/
def getInstancePinnedBlocksMemUsage(
uniqueId: String,
pinnedUsage: Long): Long = {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: param name pinnedUsage is different from what is in the description globalPinnedUsage. Lets just name this param as: totalPinnedUsage

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants